﻿using DevExpress.Utils;
using DevExpress.XtraBars;
using Inaction.Util;
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Linq;
using DevExpress.XtraLayout;
using Inaction.Message;

namespace Inaction.UI
{
    public partial class BarManager : DevExpress.XtraBars.BarManager
    {
        #region 生成按钮
        internal new void CreateItems()
        {
            BeginInit();

            #region 生成数据操作功能按钮
            SuperToolTip superToolTip_Query = new SuperToolTip();
            ToolTipItem toolTipItem_Query = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Query = new ToolTipTitleItem();
            ToolTipTitleItem toolTipTitleItem_Query1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_AddNew = new SuperToolTip();
            ToolTipItem toolTipItem_AddNew = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_AddNew = new ToolTipTitleItem();
            ToolTipTitleItem toolTipTitleItem_AddNew1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Modify = new SuperToolTip();
            ToolTipItem toolTipItem_Modify = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Modify = new ToolTipTitleItem();
            ToolTipTitleItem toolTipTitleItem_Modify1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Delete = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Delete = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Delete = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Delete1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Save = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Save = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Save = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Save1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Cancel = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Cancel = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Cancel = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Cancel1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Import = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Import = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Import = new ToolTipItem();

            SuperToolTip superToolTip_Export = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Export = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Export = new ToolTipItem();

            SuperToolTip superToolTip_Help = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Help = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Help = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Help1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Exit = new SuperToolTip();
            ToolTipTitleItem toolTipTitleItem_Exit = new ToolTipTitleItem();
            ToolTipItem toolTipItem_Exit = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Exit1 = new ToolTipTitleItem();

            SuperToolTip superToolTip_Print = new SuperToolTip();
            ToolTipItem toolTipItem_Print = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem_Print = new ToolTipTitleItem();
            ToolTipTitleItem toolTipTitleItem_Print1 = new ToolTipTitleItem();

            ToolTipItem toolTipItem11 = new ToolTipItem();
            ToolTipTitleItem toolTipTitleItem19 = new ToolTipTitleItem();
            bar = new Bar();
            BtnQuery = new BarButtonItem();
            BtnAddNew = new BarButtonItem();
            BtnModify = new BarButtonItem();
            BtnDelete = new BarButtonItem();
            BtnSave = new BarButtonItem();
            BtnCancel = new BarButtonItem();
            BtnImport = new BarButtonItem();
            BtnExport = new BarButtonItem();
            BtnPrint = new BarButtonItem();
            BtnHelp = new BarButtonItem();
            BtnExit = new BarButtonItem();
            statusBar = new Bar();
            BarItemState = new BarStaticItem();
            BarItemCurrentDetail = new BarStaticItem();
            BarItemText = new BarStaticItem();
            bar.BarName = "MainBar";
            bar.CanDockStyle = BarCanDockStyle.Top;
            bar.OptionsBar.MultiLine = false;
            bar.DockCol = 0;
            bar.DockStyle = BarDockStyle.Top;
            bar.FloatLocation = new System.Drawing.Point(139, 170);
            bar.LinksPersistInfo.AddRange(new LinkPersistInfo[] {
            new LinkPersistInfo(BtnQuery),
            new LinkPersistInfo(BtnAddNew),
            new LinkPersistInfo(BtnModify),
            new LinkPersistInfo(BtnDelete), 
            new LinkPersistInfo(BtnSave),
            new LinkPersistInfo(BtnCancel),
            new LinkPersistInfo(BtnImport, true),
            new LinkPersistInfo(BtnExport),
            new LinkPersistInfo(BtnPrint,true),
            new LinkPersistInfo(BtnHelp),
            new LinkPersistInfo(BtnExit)});
            bar.OptionsBar.AllowQuickCustomization = false;
            bar.OptionsBar.DisableClose = true;
            bar.OptionsBar.DisableCustomization = true;
            bar.OptionsBar.DrawDragBorder = false;
            bar.OptionsBar.MultiLine = true;
            bar.OptionsBar.RotateWhenVertical = false;
            bar.OptionsBar.UseWholeRow = true;
            bar.Text = "操作菜单";
            BtnQuery.Caption = "查询";
            BtnQuery.Description = "查询数据";
            BtnQuery.Id = 0;
            BtnQuery.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.F));
            BtnQuery.Name = "btnQuery";
            BtnQuery.ImageIndex = BtnQuery.LargeImageIndex = 1;
            BtnQuery.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Query.Text = "查询";
            toolTipItem_Query.LeftIndent = 6;
            toolTipItem_Query.Text = "查询数据";
            toolTipTitleItem_Query1.LeftIndent = 6;
            toolTipTitleItem_Query1.Text = "Ctrl+F";
            superToolTip_Query.Items.Add(toolTipTitleItem_Query);
            superToolTip_Query.Items.Add(toolTipItem_Query);
            superToolTip_Query.Items.Add(toolTipTitleItem_Query1);
            BtnQuery.SuperTip = superToolTip_Query;
            BtnAddNew.Caption = "新增";
            BtnAddNew.Id = 1;
            BtnAddNew.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.N));
            BtnAddNew.Name = "btnAddNew";
            BtnAddNew.ImageIndex = BtnAddNew.LargeImageIndex = 0;
            BtnAddNew.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_AddNew.Text = "新增";
            toolTipItem_AddNew.LeftIndent = 6;
            toolTipItem_AddNew.Text = "新增一条数据";
            toolTipTitleItem_AddNew1.LeftIndent = 6;
            toolTipTitleItem_AddNew1.Text = "Ctrl+N";
            superToolTip_AddNew.Items.Add(toolTipTitleItem_AddNew);
            superToolTip_AddNew.Items.Add(toolTipItem_AddNew);
            superToolTip_AddNew.Items.Add(toolTipTitleItem_AddNew1);
            BtnAddNew.SuperTip = superToolTip_AddNew;
            BtnModify.Caption = "编辑";
            BtnModify.Id = 2;
            BtnModify.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.E));
            BtnModify.Name = "btnModify";
            BtnModify.ImageIndex = BtnModify.LargeImageIndex = 4;
            BtnModify.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Modify.Text = "编辑";
            toolTipItem_Modify.LeftIndent = 6;
            toolTipItem_Modify.Text = "编辑当前数据";
            toolTipTitleItem_Modify1.LeftIndent = 6;
            toolTipTitleItem_Modify1.Text = "Ctrl+E";
            superToolTip_Modify.Items.Add(toolTipTitleItem_Modify);
            superToolTip_Modify.Items.Add(toolTipItem_Modify);
            superToolTip_Modify.Items.Add(toolTipTitleItem_Modify1);
            BtnModify.SuperTip = superToolTip_Modify;
            BtnDelete.Caption = "删除";
            BtnDelete.Id = 3;
            BtnDelete.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.Delete));
            BtnDelete.Name = "btnDelete";
            BtnDelete.ImageIndex = BtnDelete.LargeImageIndex = 2;
            BtnDelete.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Delete.Text = "删除";
            toolTipItem_Delete.LeftIndent = 6;
            toolTipItem_Delete.Text = "删除所选数据";
            toolTipTitleItem_Delete1.LeftIndent = 6;
            toolTipTitleItem_Delete1.Text = "Ctrl+Delete";
            superToolTip_Delete.Items.Add(toolTipTitleItem_Delete);
            superToolTip_Delete.Items.Add(toolTipItem_Delete);
            superToolTip_Delete.Items.Add(toolTipTitleItem_Delete1);
            BtnDelete.SuperTip = superToolTip_Delete;
            BtnCancel.Caption = "取消";
            BtnCancel.Id = 4;
            BtnCancel.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.Z));
            BtnCancel.Name = "btnCancel";
            BtnCancel.ImageIndex = BtnCancel.LargeImageIndex = 8;
            BtnCancel.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Cancel.Text = "取消";
            toolTipItem_Cancel.LeftIndent = 6;
            toolTipItem_Cancel.Text = "取消操作";
            toolTipTitleItem_Cancel1.LeftIndent = 6;
            toolTipTitleItem_Cancel1.Text = "Ctrl+Z";
            superToolTip_Cancel.Items.Add(toolTipTitleItem_Cancel);
            superToolTip_Cancel.Items.Add(toolTipItem_Cancel);
            superToolTip_Cancel.Items.Add(toolTipTitleItem_Cancel1);
            BtnCancel.SuperTip = superToolTip_Cancel;
            BtnSave.Caption = "保存";
            BtnSave.Id = 6;
            BtnSave.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.S));
            BtnSave.Name = "btnSave";
            BtnSave.ImageIndex = BtnSave.LargeImageIndex = 3;
            BtnSave.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Save.Text = "保存";
            toolTipItem_Save.LeftIndent = 6;
            toolTipItem_Save.Text = "保存数据";
            toolTipTitleItem_Save1.LeftIndent = 6;
            toolTipTitleItem_Save1.Text = "Ctrl+S";
            superToolTip_Save.Items.Add(toolTipTitleItem_Save);
            superToolTip_Save.Items.Add(toolTipItem_Save);
            superToolTip_Save.Items.Add(toolTipTitleItem_Save1);
            BtnSave.SuperTip = superToolTip_Save;
            BtnImport.Caption = "导入";
            BtnImport.Id = 7;
            BtnImport.Name = "btnImport";
            BtnImport.ImageIndex = BtnImport.LargeImageIndex = 6;
            BtnImport.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Import.Text = "导入";
            toolTipItem_Import.LeftIndent = 6;
            toolTipItem_Import.Text = "导入数据";
            superToolTip_Import.Items.Add(toolTipTitleItem_Import);
            superToolTip_Import.Items.Add(toolTipItem_Import);
            BtnImport.SuperTip = superToolTip_Import;
            BtnExport.Caption = "导出";
            BtnExport.Id = 8;
            BtnExport.Name = "btnExport";
            BtnExport.ImageIndex = BtnExport.LargeImageIndex = 7;
            BtnExport.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Export.Text = "导出";
            toolTipItem_Export.LeftIndent = 6;
            toolTipItem_Export.Text = "导出数据";
            superToolTip_Export.Items.Add(toolTipTitleItem_Export);
            superToolTip_Export.Items.Add(toolTipItem_Export);
            BtnExport.SuperTip = superToolTip_Export;
            BtnPrint.Caption = "打印";
            BtnPrint.Id = 9;
            BtnPrint.Name = "btnPrint";
            BtnPrint.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P));
            BtnPrint.ImageIndex = BtnPrint.LargeImageIndex = 5;
            BtnPrint.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Print.Text = "打印";
            toolTipItem_Print.LeftIndent = 6;
            toolTipItem_Print.Text = "Ctrl+P";
            superToolTip_Print.Items.Add(toolTipTitleItem_Print);
            superToolTip_Print.Items.Add(toolTipItem_Print);
            BtnPrint.SuperTip = superToolTip_Print;
            BtnHelp.Caption = "帮助";
            BtnHelp.Id = 10;
            BtnHelp.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.H));
            BtnHelp.Name = "btnHelp";
            BtnHelp.ImageIndex = BtnHelp.LargeImageIndex = 10;
            BtnHelp.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Help.Text = "帮助";
            toolTipItem_Help.LeftIndent = 6;
            toolTipItem_Help.Text = "显示帮助信息";
            toolTipTitleItem_Help1.LeftIndent = 6;
            toolTipTitleItem_Help1.Text = "Ctrl+H";
            superToolTip_Help.Items.Add(toolTipTitleItem_Help);
            superToolTip_Help.Items.Add(toolTipItem_Help);
            superToolTip_Help.Items.Add(toolTipTitleItem_Help1);
            BtnHelp.SuperTip = superToolTip_Help;
            BtnExit.Caption = "退出";
            BtnExit.Id = 11;
            BtnExit.ItemShortcut = new BarShortcut((System.Windows.Forms.Keys.Control |  System.Windows.Forms.Keys.Q));
            BtnExit.Name = "btnExit";
            BtnExit.ImageIndex = BtnExit.LargeImageIndex = 9;
            BtnExit.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            toolTipTitleItem_Exit.Text = "退出";
            toolTipItem_Exit.LeftIndent = 6;
            toolTipItem_Exit.Text = "退出窗口";
            toolTipTitleItem_Exit1.LeftIndent = 6;
            toolTipTitleItem_Exit1.Text = "Ctrl+Q";
            superToolTip_Exit.Items.Add(toolTipTitleItem_Exit);
            superToolTip_Exit.Items.Add(toolTipItem_Exit);
            superToolTip_Exit.Items.Add(toolTipTitleItem_Exit1);
            BtnExit.SuperTip = superToolTip_Exit;
            statusBar.BarName = "StatusBar";
            statusBar.CanDockStyle = BarCanDockStyle.Bottom;
            statusBar.DockCol = 0;
            statusBar.DockStyle = BarDockStyle.Bottom;
            statusBar.LinksPersistInfo.AddRange(new LinkPersistInfo[] {
            new LinkPersistInfo(BarItemState),
            new LinkPersistInfo(BarItemCurrentDetail),
            new LinkPersistInfo(BarItemText)});
            statusBar.OptionsBar.AllowQuickCustomization = false;
            statusBar.OptionsBar.DisableClose = true;
            statusBar.OptionsBar.DisableCustomization = true;
            statusBar.OptionsBar.DrawDragBorder = false;
            statusBar.OptionsBar.RotateWhenVertical = false;
            statusBar.OptionsBar.UseWholeRow = true;
            statusBar.Text = "状态栏";
            BarItemState.Caption = "操作状态：";
            BarItemState.Id = 0;
            BarItemState.Name = "barItemState";
            BarItemState.TextAlignment = System.Drawing.StringAlignment.Near;
            BarItemCurrentDetail.AutoSize = BarStaticItemSize.Content;
            BarItemCurrentDetail.Id = 2;
            BarItemCurrentDetail.Name = "barItemCurrentDetail";
            BarItemCurrentDetail.TextAlignment = System.Drawing.StringAlignment.Near;
            BarItemCurrentDetail.Width = 150;
            BarItemText.AutoSize = BarStaticItemSize.Spring;
            BarItemText.Id = 3;
            BarItemText.Name = "barItemText";
            BarItemText.TextAlignment = System.Drawing.StringAlignment.Near;
            BarItemText.ItemAppearance.Normal.ForeColor = System.Drawing.Color.Red;
            BarItemText.ItemAppearance.Normal.Options.UseForeColor = true;

            this.Bars.AddRange(new Bar[] {
            bar,
            statusBar});
            this.Items.AddRange(new BarItem[] {
            BtnQuery,
            BtnAddNew,
            BtnModify,
            BtnDelete, 
            BtnSave,
            BtnCancel,
            BtnExit,
            BtnHelp,
            BtnImport,
            BtnExport,
            BtnPrint,
            BarItemCurrentDetail,
            BarItemState,
            BarItemText});
            this.MainMenu = bar;
            this.MaxItemId = 2147483647;
            this.MdiMenuMergeStyle = BarMdiMenuMergeStyle.Never;
            this.StatusBar = statusBar;
            base.Container.Add(bar, bar.BarName);
            base.Container.Add(BtnQuery, BtnQuery.Name);
            base.Container.Add(BtnAddNew, BtnAddNew.Name);
            base.Container.Add(BtnModify, BtnModify.Name);
            base.Container.Add(BtnDelete, BtnDelete.Name);
            base.Container.Add(BtnSave, BtnSave.Name);
            base.Container.Add(BtnCancel, BtnCancel.Name);
            base.Container.Add(BtnImport, BtnImport.Name);
            base.Container.Add(BtnExport, BtnExport.Name);
            base.Container.Add(BtnPrint, BtnPrint.Name);
            base.Container.Add(BtnHelp, BtnHelp.Name);
            base.Container.Add(BtnExit, BtnExit.Name);
            base.Container.Add(statusBar, statusBar.BarName);
            base.Container.Add(BarItemState, BarItemState.Name);
            base.Container.Add(BarItemCurrentDetail, BarItemCurrentDetail.Name);
            base.Container.Add(BarItemText, BarItemText.Name);
            #endregion

            if (Form != null && !Form.Controls.Cast<Control>().Any(p => p is LayoutControl))
            {
                var c = new LayoutControl();
                c.Dock = DockStyle.Fill;
                Form.Controls.Add(c);
                base.Container.Add(c);
                c.Site.Name = "layoutControl";
            }

            base.CreateItems();

            EndInit();
        }
        #endregion

        #region 数据操作事件
        private void RegisteEvent()
        {
            if (IsDesignMode || BtnAddNew == null) return;
            BtnAddNew.ItemClick -= btnAddNew_ItemClick;
            BtnAddNew.ItemClick += btnAddNew_ItemClick;
            BtnQuery.ItemClick -= btnQuery_ItemClick;
            BtnQuery.ItemClick += btnQuery_ItemClick;
            BtnModify.ItemClick -= btnModify_ItemClick;
            BtnModify.ItemClick += btnModify_ItemClick;
            BtnCancel.ItemClick -= btnCancel_ItemClick;
            BtnCancel.ItemClick += btnCancel_ItemClick;
            BtnDelete.ItemClick -= btnDelete_ItemClick;
            BtnDelete.ItemClick += btnDelete_ItemClick;
            BtnSave.ItemClick -= btnSave_ItemClick;
            BtnSave.ItemClick += btnSave_ItemClick;
            BtnImport.ItemClick -= btnImport_ItemClick;
            BtnImport.ItemClick += btnImport_ItemClick;
            BtnExport.ItemClick -= btnExport_ItemClick;
            BtnExport.ItemClick += btnExport_ItemClick;
            BtnExit.ItemClick -= btnExit_ItemClick;
            BtnExit.ItemClick += btnExit_ItemClick;
            BtnPrint.ItemClick -= btnPrint_ItemClick;
            BtnPrint.ItemClick += btnPrint_ItemClick;
            BtnHelp.ItemClick -= btnHelp_ItemClick;
            BtnHelp.ItemClick += btnHelp_ItemClick;
            operateState = BarManagerState.None;

            BtnQuery.Enabled = true;
            BtnAddNew.Enabled = true;
            BtnModify.Enabled = false;
            BtnDelete.Enabled = false;
            BtnSave.Enabled = false;
            BtnCancel.Enabled = false;
            BtnImport.Visibility = BarItemVisibility.Never;
            BtnExit.Enabled = true;
            BtnExport.Enabled = false;
            BarItemState.Caption = string.Empty;
            BarItemText.ItemAppearance.Normal.ForeColor = System.Drawing.Color.OrangeRed;
            this.ItemPress += (a, b) => { (Form as Form).ValidateChildren(ValidationConstraints.Enabled); };
        }

        #region 按钮事件
        void btnQuery_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            if (EditMode && MasterBindingInfo != null && MasterBindingInfo.IsDirty)
            {
                if (MessageBox.Show("当前窗口处于编辑状态，查询会取消当前的操作！！" + Environment.NewLine
                    + "您确定要查询吗？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) return;
            }
            ShowWaitDialog("正在查询...");
            try
            {
                Query();
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询出错\r\n" + ex.GetMessage());
            }
            finally
            {
                HideWaitDialog();
            }
        }
        void btnAddNew_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            AddNew(CurrentBindingInfo);
        }
        void btnModify_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            Modify(CurrentBindingInfo);
        }
        void btnSave_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            try
            {
                ShowWaitDialog("正在保存...");
                if (Save())
                {
                    MessageHost.ShowMessage("保存成功！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存出错\r\n" + ex.GetMessage());
            }
            finally
            {
                HideWaitDialog();
            }
        }
        void btnDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            try
            {
                Delete(CurrentBindingInfo);
                ApplyFormRules();
            }
            catch (Exception ex)
            {
                MessageBox.Show("删除出错\r\n"
                    + ex.Message
                    + ex.InnerException != null ? "\r\n" + ex.InnerException.Message : "");
            }
            finally
            {
                HideWaitDialog();
            }
        }
        void btnCancel_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            Cancel();
        }
        void btnExport_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            Export();
        }
        void btnImport_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            if (Importing != null)
            {
                Importing();
            }
        }
        void btnPrint_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            Print();
        }
        void btnHelp_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            Help();
        }
        void btnExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!e.Item.Enabled || e.Item.Visibility != BarItemVisibility.Always)
            {
                return;
            }
            if (EditMode && MasterBindingInfo != null && MasterBindingInfo.IsDirty)
            {
                if (MessageBox.Show("当前窗口处于编辑状态，关闭窗口会取消当前的操作！" + Environment.NewLine
                    + "您确定要关闭吗？", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    return;
                }
            }
            var form = this.GetForm();
            if (form != null)
            {
                form.AutoValidate = AutoValidate.Disable;
                form.Close();
            }
        }
        #endregion

        #endregion

        #region 操作事件
        [Category("Inaction")]
        [Description("查询数据时触发")]
        public event EventHandler<BarItemClickEventArgs> Querying;
        [Category("Inaction")]
        [Description("查询数据后触发")]
        public event EventHandler<BarItemClickedEventArgs> Queryed;
        [Category("Inaction")]
        [Description("新增数据时触发")]
        public event EventHandler<BarItemClickEventArgs> AddNewing;
        [Category("Inaction")]
        [Description("新增数据后触发")]
        public event EventHandler<BarItemClickedEventArgs> AddNewed;
        [Category("Inaction")]
        [Description("取消编辑时触发")]
        public event EventHandler<BarItemClickEventArgs> Canceling;
        [Category("Inaction")]
        [Description("取消编辑后触发")]
        public event EventHandler<BarItemClickedEventArgs> Canceled;
        [Category("Inaction")]
        [Description("删除数据时触发")]
        public event EventHandler<BarItemClickEventArgs> Deleting;
        [Category("Inaction")]
        [Description("删除数据后触发")]
        public event EventHandler<BarItemClickedEventArgs> Deleted;
        [Category("Inaction")]
        [Description("导入数据时触发")]
        public event Action Importing;
        [Category("Inaction")]
        [Description("导出数据时触发")]
        public event Action Exporting;
        [Category("Inaction")]
        [Description("打印时触发")]
        public event Action Printing;
        [Category("Inaction")]
        [Description("编辑数据时触发")]
        public event EventHandler<BarItemClickEventArgs> Modifying;
        [Category("Inaction")]
        [Description("数据状态改后触发")]
        public event EventHandler<BarItemClickedEventArgs> OperateStateChanged;
        [Category("Inaction")]
        [Description("保存数据时触发")]
        public event EventHandler<BarItemClickEventArgs> Saving;
        [Category("Inaction")]
        [Description("保存数据后触发")]
        public event EventHandler<BarItemClickedEventArgs> Saved;
        [Category("Inaction")]
        [Description("帮助按钮点击时触发")]
        public static event EventHandler<HelpEventArgs> Helping;
        [Category("Inaction")]
        [Description("当前数据源改变时触发")]
        public event EventHandler<BindingChangeEventArgs> CurrentBindingChanging;
        [Category("Inaction")]
        [Description("当前数据源改变后触发")]
        public event EventHandler<BindingChangeEventArgs> CurrentBindingChanged;
        [Category("Inaction")]
        [Description("应用规则后触发")]
        public event EventHandler<EventArgs> FormRulesApplied;
        #endregion
    }
}
